package com.game.controllers;
import com.game.objects.Environment;
import com.jme.math.FastMath;
import com.jme.math.Vector3f;
import com.jme.scene.Controller;
import com.jme.scene.TriMesh;

public class ShootController extends Controller{
	private TriMesh bullet;
	private Vector3f direction; 
	private final float speed = 200f;
	private float lifeTime=5;
	private Environment ev;
	public ShootController(TriMesh bullet, Environment ev, Vector3f position, Vector3f direction){
		this.ev=ev;
		this.bullet = bullet;
		bullet.setLocalTranslation(new Vector3f(position));
		this.direction = direction.normalize();
	}
	public void update(float time) {
		lifeTime -= time;
		if (lifeTime < 0) {
			bullet.getParent().detachChild(bullet);
			bullet.removeController(this);
			return;
		}
		if(ev.checkSimpleCollision(bullet)){
			bullet.getParent().detachChild(bullet);
			bullet.removeController(this);
			return;
		}

		bullet.getLocalTranslation().addLocal(direction.mult(time * speed));
	}
}